{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "34d39154",
   "metadata": {},
   "source": [
    "# Problem 14.01 Joule-Thomson Coefficient of Nitrogen  Using the Virial Equation and the SRK EOS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c13e0a8",
   "metadata": {},
   "source": [
    "What is the Joule-Thomson coefficient of nitrogen at 150 K and 10 atm? Use a) the Tsonopoulos virial method, and b) the SRK equation of state."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4fd23152",
   "metadata": {},
   "source": [
    "## Solution"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4788233f",
   "metadata": {},
   "source": [
    "This requires configuring both phase objects and calling the appropriate method only."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2594afc8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.constants import atm\n",
    "from thermo import ChemicalConstantsPackage, SRKMIX, CEOSGas, VirialCSP, VirialGas\n",
    "fluid = 'nitrogen'\n",
    "constants, correlations = ChemicalConstantsPackage.from_IDs([fluid])\n",
    "\n",
    "T = 150\n",
    "P = 10*atm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "da431987",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Joule Thomson coefficient of nitrogen for the virial prediction is 9.46155e-06 K/Pa\n"
     ]
    }
   ],
   "source": [
    "model = VirialCSP(Tcs=constants.Tcs, Pcs=constants.Pcs, Vcs=constants.Vcs, \n",
    "                  omegas=constants.omegas, B_model='VIRIAL_B_TSONOPOULOS',\n",
    "                  C_model='VIRIAL_C_ZERO')\n",
    "virial_gas = VirialGas(model=model, T=T, P=P, zs=[1], HeatCapacityGases=correlations.HeatCapacityGases)\n",
    "print(f\"The Joule Thomson coefficient of nitrogen for the virial prediction is {virial_gas.Joule_Thomson():g} K/Pa\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "88c18e7a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Joule Thomson coefficient of nitrogen for the SRK prediction is 2.13967e-06 K/Pa\n"
     ]
    }
   ],
   "source": [
    "eos_kwargs = dict(Tcs=constants.Tcs, Pcs=constants.Pcs, omegas=constants.omegas)\n",
    "gas = CEOSGas(SRKMIX, HeatCapacityGases=correlations.HeatCapacityGases, eos_kwargs=eos_kwargs)\n",
    "print(f\"The Joule Thomson coefficient of nitrogen for the SRK prediction is {gas.Joule_Thomson():g} K/Pa\")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
